package 代码随想录.数组.有序数组的平方;

class Solution {
    public int[] sortedSquares(int[] nums) {
        int right = nums.length-1;
        int left = 0;
        int[] result = new int[nums.length];
        int index = nums.length-1;
        while(left <= right) {
            if(nums[left]*nums[left] > nums[right]*nums[right]) {
                result[index--] = nums[left]*nums[left];
                ++left;
            }else {
                result[index--] = nums[right]*nums[right];
                --right;
            }
        } //while
        return result;
    } //sortSquares()
    public static void main(String[] args) {
        
    }    
}
